#include <stdio.h>
#include <stdlib.h>

// step 1# DisNode 链表节点存放子分销商的数据
typedef struct DisNode {
    int id;
    struct DisNode *next;
} DisNode;
// step 2# Distributors 结构体存放每个分销商的收入和子分销商链表
typedef struct Distributors {
    int income;
    DisNode *childDistributors;
} Distributors;

Distributors *distributors[1000];
// step 3# ids 数组负责存放所有分销商的 id
// childToParent 数组负责存放所有分销商的父 id
int ids[1000];
int idsCount = 0;
int childToParent[1000];

void addChild(int childId, int parentId) {
    DisNode *childNode = (DisNode *)malloc(sizeof(DisNode));
    childNode->id = childId;
    childNode->next = distributors[parentId]->childDistributors;
    distributors[parentId]->childDistributors = childNode;
}

void calcTotalIncome(int parentId) {
    DisNode *childNode = distributors[parentId]->childDistributors;
    while(childNode != NULL) {
        calcTotalIncome(childNode->id);
        int add = ( distributors[childNode->id]->income / 100 ) * 15;
        distributors[parentId]->income += add;
        childNode = childNode->next;
    }
}

int main() {
    // step 4# 初始化 ids childToParent distributors
    for(int i = 0; i < 1000; i++) {
        ids[i] = -1;
        childToParent[i] = -1;
        distributors[i] = NULL;
    }

    int num;
    scanf("%d", &num);
    for(int i = 0; i < num; i++) {
        int childId, parentId, income;
        // step 5# 处理输入的数据，如果 id 没有创建，则创建相应的信息
        scanf("%d %d %d", &childId, &parentId, &income);
        if (distributors[childId] == NULL) {
            distributors[childId] = (Distributors *)malloc(sizeof(Distributors));
            distributors[childId]->income = 0;
            distributors[childId]->childDistributors = NULL;
            ids[idsCount++] = childId;
        }
        if (distributors[parentId] == NULL) {
            distributors[parentId] = (Distributors *)malloc(sizeof(Distributors));
            distributors[parentId]->income = 0;
            distributors[parentId]->childDistributors = NULL;
            ids[idsCount++] = parentId;
        }
        distributors[childId]->income = income;
        childToParent[childId] = parentId;
        // step 6# 构建子分销商的链表
        addChild(childId, parentId);
    }
    // step 7# 找 boss 的 id
    int bossId = -1;
    for(int i = 0; i < idsCount; i++) {
        // error 1# 下标不是 i， 而是 ids[i]
        if (childToParent[ids[i]] == -1) {
            bossId = ids[i];
            break;
        }
    }
    // step 8# 从 boss 开始递归计算总收入
    calcTotalIncome(bossId);

    printf("%d %d", bossId, distributors[bossId]->income);

    return 0;
}